#ifndef CLUSTER_H
#define CLUSTER_H

#include <cassert>
#include <iostream>
#include <sstream>
#include <list>
#include <vector>
#include "string_util.h"

using namespace std;

class Node
{
  public:
    Node():id(-1),v(0) {}
    Node( int id, float v):id(id),v(v){}
    // construct from string : id:v
    Node(const string s){
        sscanf(s.c_str(), "%d:%f", &id, &v);
        assert(id >0 && v > 0);
    }
    void set_v(float v){this->v = v;}
  public:    
    int id;
    float v;
};

// cluster is a vector of Nodes
class Cluster
{
  public:
    Cluster(int id):m_id(id) {}
    Cluster(int id, string s);
    
    const int id() {return m_id;}
    const int id() const {return m_id;}
    int size() {return m_nodes.size();}
    const list<Node>& nodes() const {return m_nodes;}
    
    void insert(const Node& node);

    bool has_node(const Node& node) const;
    
    float sim(const Cluster& c);
    
    void combine(const Cluster& c);

    //test
    void print(){
        for(list<Node>::iterator it = m_nodes.begin();
            it != m_nodes.end();
            ++it){
            printf("%d:%f;", it->id, it->v);
        }
        printf("\n");
    }
  private:
    int m_id;
    list<Node> m_nodes;
};

#endif
